package com.molichuxing.services.business.service.impl;

import java.time.ZoneOffset;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.molichuxing.services.business.dto.request.create.OrderDelayCreateBizDto;
import com.molichuxing.services.business.service.OrderDelayBizService;
import com.molichuxing.services.delay.OrderDelay;
import com.molichuxing.services.delay.OrderDelayTask;

/**
 * 订单延时任务service
 * 
 * @author zoumingyu
 * @date 2019年11月7日
 *
 */
@Service("orderDelayBizService")
public class OrderDelayBizServiceImpl implements OrderDelayBizService {

	@Resource
	private OrderDelayTask orderDelayTask;

	/**
	 * 新增延时任务
	 * 
	 * @param createDto
	 * @return
	 */
	@Override
	public boolean create(OrderDelayCreateBizDto createBizDto) {
		long timeout = createBizDto.getExpireDate().toInstant(ZoneOffset.of("+8")).toEpochMilli();
		OrderDelay orderDelay = new OrderDelay(createBizDto.getOrderCode(), createBizDto.getUserId(), timeout);
		return orderDelayTask.create(orderDelay);
	}

	/**
	 * 删除延时任务
	 * 
	 * @param orderCode
	 *            订单号
	 * @return
	 */
	@Override
	public boolean delete(Long orderCode) {
		return orderDelayTask.delete(orderCode);
	}
}
